// 封装axios
import axios from 'axios'; // 引入axios

//  请求拦截器
axios.interceptors.request.use((config) => {
	// 登录请求携带 验证码
	if('/bms/user/api/v1/login' === config.url){
		let verificationCode = sessionStorage.getItem('verificationCode');
    let verificationCodeId = sessionStorage.getItem('verificationCodeId');
		if(verificationCode && verificationCodeId){
			config.headers.verificationCode = verificationCode;
      config.headers.verificationCodeId = verificationCodeId;
		}
	} else {    // 其他接口
    let token = localStorage.getItem('token')
		if (token) {
			config.headers.Authorization = token
		}
  }
  
  return config

})

//  响应拦截器
axios.interceptors.response.use(res => {
	// 成功响应的拦截
	return Promise.resolve(res)
}, err => {
	return Promise.reject(err)
})
